<%-- 
    Document   : SearchPeople
    Created on : Dec 8, 2011, 5:59:53 PM
    Author     : hendrikde
--%>

<%@page import="java.util.Enumeration"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.util.ArrayList" %>
<% if(session.getAttribute("LoggedIn")==null)
       {
    response.sendRedirect("index.html");
    return;
        }

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <title>Search People</title>
        <script type="text/javascript">
            
function username_click(txt)
{
    document.forms[txt].submit();
}

function username_mouseover(obj)
{
	obj.style.backgroundColor="#6699FF";
}

function username_mouseout(obj)
{
	obj.style.backgroundColor="#CCCCCC";
}
            </script>
    </head>
    <body>
    <h1>Search Users</h1>
    <%
    String circle=null;
    Enumeration<String> atts = session.getAttributeNames();
    while(atts.hasMoreElements())
    {
        if(atts.nextElement().equals("CIRC"))
            circle = session.getAttribute("CIRC").toString();
    }
    int cur_circle;
    if (circle != null) {
        cur_circle=Integer.parseInt(circle);
       }
    else
        cur_circle=-1;
    
    %>
    <form name="SearchUsers" action="DoUserSearch.jsp" method="Post">
            Name: <input type="text" name="custname"/><input type="submit" value="Search"/>
        </form><input type="button" value="Return" onclick="window.location='gohome.jsp'"/>
        <%
        ArrayList<DBClasses.SearchNode> sn = (ArrayList<DBClasses.SearchNode>) session.getAttribute("UserSet");
        if (sn !=null) {%>
        <table width="800" border="0">
            <tr><th>Search Results</th></tr>
            <tr><td>Name</td></tr>
            <%
        for (int i = 0; i < sn.size(); i++) {
            String[] userdat = sn.get(i).getWordsSplit();
    %>
            <tr bgcolor="#CCCCCC" onclick ="username_click('<%="user" +i%>')" onmouseover="username_mouseover(this)" onmouseout="username_mouseout(this)">
            
            <td ><form name="<%="seeuserhist" + i%>" action="PublicProfile.jsp" method="post">
                    <input name="PERS" type="hidden" value="<%=sn.get(i).getID()%>"/>
                    <input type="submit" value="View Public Profile"/>
                <%=userdat[0]%> <%=userdat[1]%></form></td>
            <%
            if (cur_circle != -1) { %>
            <td><form name="<%="adduser" +i%>" action="inviteToCircle.jsp" method="post">
                <input name="PERS" type="hidden" value="<%=sn.get(i).getID()%>"/>
                <input name="CIRC" type="hidden" value="<%=cur_circle%>"/>
                <input type="button" value="Add to circle" onclick="document.<%="adduser" +i%>.submit()"/>
                </form></td>
                <% } %>
            </tr>
                    <%
        }
        %></table>
        <%
        session.setAttribute("UserSet", null);       
        }
        %>
    </body>
</html>
